﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CC98
{
    public partial class InitializeProcessor
    {
        public async Task StartAsync()
        {
            await Task.Run(() =>
                {
                    foreach (var stage in Stages)
                    {
                        this.OnProgressChanged(stage.Name);
                        stage.Handler.RunSynchronously();
                    }
                });
        }

        protected void OnProgressChanged(string stageResourceName)
        {
            if (this.ProgressChanged != null)
                this.ProgressChanged(this, new InitializeProcessorProgressChangedEventArgs(stageResourceName));
        }

        public event EventHandler<InitializeProcessorProgressChangedEventArgs> ProgressChanged;
    }

    public class InitializeStage
    {
        public string Name { get; set; }

        public Task Handler { get; set; }
    }

    public class InitializeProcessorProgressChangedEventArgs : EventArgs
    {
        public InitializeProcessorProgressChangedEventArgs(string stageResourceName)
        {
            this.StageResourceName = stageResourceName;
        }

        public string StageResourceName { get; private set; }
    }
}
